local NetworkSenderClass = class()
NetworkSender = NetworkSenderClass.new()

function NetworkSenderClass:Init()

end

function NetworkSenderClass:AskLogin(Mail, Password, Platform)
    local player = EntityManager:GetEntity(Mail)
    if player == nil then
        player = EntityManager:CreateEntity(Mail, true)
        player.Mail = Mail
        player.Password = Password
        player.Platform = Platform
        player.Token = ""
        player.RoomID = nil
    end

    local login = GC_LS_pb.AskLogin()
    login.msgid = GC_LS_pb.GC2LS_AskLogin
    login.platform = Platform
    login.mail = Mail
    login.password = Password
    
    local msg = login:SerializeToString()
    NetworkManager.Instance:SendMsg(msg, login.msgid)
end

function NetworkSenderClass:AskLoginGate()
    local player = EntityManager:GetPlayer()
    if player.Mail == nil or player.Password == nil then
        Debug.LogError("登陆信息有误")
        return
    end
    local login = GC_GS_pb.TokenLogin()
    login.msgid = GC_GS_pb.GC2GS_TokenLogin
    login.mail = player.Mail
    login.password = player.Password
    login.token = player.Token
    
    local msg = login:SerializeToString()
    NetworkManager.Instance:SendMsg(msg, login.msgid)
end

function NetworkSenderClass:AskUserInfo()
    local msgInfo = CS_GS_pb.UserInfo()
    msgInfo.msgid = CS_GS_pb.CS2GS_UserInfo
    msgInfo.name = ""
    local msg = msgInfo:SerializeToString()
    NetworkManager.Instance:SendMsg(msg, msgInfo.msgid)
end

function NetworkSenderClass:StartMatch()
    local player = EntityManager:GetPlayer()
    local msgInfo = CS_GS_pb.StartMatch()
    msgInfo.msgid = CS_GS_pb.CS2GS_StartMatch
    msgInfo.mail = player.Mail
    msgInfo.result = 0
    local msg = msgInfo:SerializeToString()
    NetworkManager.Instance:SendMsg(msg, msgInfo.msgid)
end

function NetworkSenderClass:DirectionMove(Direction)
    local player = EntityManager:GetPlayer()
    local msgInfo = CS_GS_pb.Direction()
    msgInfo.msgid = CS_GS_pb.CS2GS_Direction
    msgInfo.mail = player.Mail
    msgInfo.roomid = player.RoomID
    msgInfo.direction = Direction
    local msg = msgInfo:SerializeToString()
    NetworkManager.Instance:SendMsg(msg, msgInfo.msgid)
end
